package com.palm.easy;

import com.palm.easy.util.Captcha;
import org.noear.solon.Solon;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.MethodType;
import org.noear.solon.core.handle.Result;
import java.io.IOException;


public class ServerApp {
    public static void main(String[] args) throws IOException {
        Solon.start(ServerApp.class, args, app -> {
            // 用于集群反向部署
            app.enableWebSocketD(true);
            // 验证码
            app.add("captcha", MethodType.GET, ctx -> Captcha.captcha(ctx));
            // 自动跳转首页
            app.add("/", MethodType.GET, ctx -> ctx.redirect("index.html"));
            // 500错误输出
            app.onError(e -> {
                Context ctx = Context.current();
                if (ctx != null) {
                    if (ctx.action() != null) {
                        try {
                            ctx.render(Result.failure(500, e.getMessage()));
                        } catch (Throwable ex) {
                            ex.printStackTrace();
                        }
                    }
                }
            });
        });
//        HealthCheckResult result= HealthChecker.check();
//        System.out.println(JSON.toJSONString(result));
    }
}
